package com.zzyl.nursing.controller.member;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.ss.formula.functions.Count;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{

    @Autowired
    private IReservationService reservationService;


    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        int count=reservationService.getCancelledReservationCount();
        return R.ok(count);
    }


    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余的预约次数")
    public R<List<TimeVo>> countByTime(Long time) {
        List<TimeVo> count=reservationService.countByTime(time);
        return R.ok(count);
    }



    /**
     * 分页查询预约信息列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "获取预约信息列表")
    public  AjaxResult list(Reservation reservation)
    {
        //TableDataInfo<List<Reservation>>
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return AjaxResult.success(getDataTable(list)) ;
    }

    @PutMapping("/{id}/cancel")
    @ApiModelProperty("取消预约")
    public AjaxResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return AjaxResult.success();
    }

    /**
     * 新增预约信息
     */
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody ReservationDto dto)
    {
        return toAjax(reservationService.insertReservation(dto));
    }

}